package cn.fayang.ymcc.mq;

import cn.fayang.ymcc.domain.MessageStation;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class StationMessageProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     *
     * @param messageStation
     * @return
     */
    public boolean sendMessage(MessageStation messageStation){
        //将mediaFile对象转换成JSON字符串
        String mediaFileJsonStr = JSON.toJSONString(messageStation);
        //发送同步消息
        SendResult sendResult = rocketMQTemplate.syncSend("common-topic:common-tags", mediaFileJsonStr);
        SendStatus sendStatus = sendResult.getSendStatus();
        return sendStatus==SendStatus.SEND_OK;
    }


}
